﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using ScrumTable.Common;
using ScrumTable.DL.Data.Generic.Cache;
using ScrumTable.DL.Data.Schema;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

#endregion

namespace ScrumTable.DL.Data.Generic
{
    /// <summary>
    /// This class specifies the project data wrapper for a cache field defintion type.
    /// </summary>
    /// <remarks>The implementation of the data object class follows the Anything pattern.</remarks>
    internal class MetaDataObject : DataObjectBase<MetaSchema, CacheFieldDefinition>
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private readonly CacheFieldDefinition _data;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the corresponding typed data schema (e.g. UserStorySchema / TaskSchema / ...).
        /// </summary>
        protected override sealed MetaSchema TypedSchema { get { return ScrumTableSchema.MetaSchema; } }

        /// <summary>
        /// Gets the underlying data element instance.
        /// </summary>
        protected override CacheFieldDefinition Element { get { return _data; } }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new DataObject instance, no public constructor
        /// needed.
        /// </summary>
        /// <param name="parent">Specifies the parent data access object.</param>
        /// <param name="fieldDefinition">Specifies the underlying workItemType instance.</param>
        internal MetaDataObject(
            DataAccessObjectBase parent,
            CacheFieldDefinition fieldDefinition)
            : base(parent)
        {
            PreCondition.AssertNotNull(fieldDefinition, "fieldDefinition");

            _data = fieldDefinition;

            NameSchemaMappings.Add(TypedSchema.Name, GetName);
            NameSchemaMappings.Add(TypedSchema.MappedName, GetMappedName);
            NameSchemaMappings.Add(TypedSchema.DisplayName, GetDisplayName);
            NameSchemaMappings.Add(TypedSchema.AllowedValues, GetAllowedValues);
            NameSchemaMappings.Add(TypedSchema.DefaultValue, GetDefaultValue);
            NameSchemaMappings.Add(TypedSchema.FieldType, GetFieldType);
            NameSchemaMappings.Add(TypedSchema.FieldTypeFormat, GetFieldTypeFormat);
            NameSchemaMappings.Add(TypedSchema.SuggestedValues, GetSuggestedValues);
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        private object GetName(SchemaBase schema) { return _data.Name; }
        private object GetMappedName(SchemaBase schema) { return _data.BackEndId; }
        private object GetDisplayName(SchemaBase schema) { return _data.DisplayName; }
        private object GetAllowedValues(SchemaBase schema) { return _data.AllowedValues; }
        private object GetDefaultValue(SchemaBase schema) { return _data.DefaultValue; }
        private object GetFieldType(SchemaBase schema) { return _data.FieldType; }
        private object GetFieldTypeFormat(SchemaBase schema) { return _data.FieldTypeFormat; }
        private object GetSuggestedValues(SchemaBase schema) { return _data.SuggestedValues; }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}